
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    "index_url": "classes/category/index",
                    "add_url": "classes/category/add",
                    "edit_url": "classes/category/edit",
                    "del_url": "classes/category/del",
                    "multi_url": "classes/category/multi",
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                commonSearch: true,
                searchFormVisible: true,
                sortName: 'sort',
                sortOrder: 'asc',
                columns: [
                    [
                        {field: 'state', checkbox: true, },
                        {field: 'school_name', title: __('学校'), operate: false},
                        {
                            field: 'school_id', title: __('学校'), searchList: function (column) {
                                return Template('schoolTpl', {});
                            }, formatter: function (value, row, index) {
                                return '无';
                            }, visible: false
                        },
                        {field: 'name', title: __('Name')},
                        {field: 'image', title: __('图片'), formatter: Table.api.formatter.image, operate: false},
                        {field: 'sort', title: __('排序'), operate:false, sortable: true,},
                        {
                            field: 'status',
                            title: __('是否显示'),
                            align: 'center',
                            operate: false,
                            formatter: Table.api.formatter.toggle
                        },
                        {field: 'behaviors_count', title: __('行为数量'), operate:false},
                        {
                            field: 'created_at',
                            title: __('Create time'),
                            sortable: true,
                            formatter: Table.api.formatter.datetime,
                            operate: 'RANGE',
                            addclass: 'datetimerange'
                        },
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},
                    ]
                ],
            });

            // 为表格绑定事件
            Table.api.bindevent(table);


        },
        add: function () {
            Form.api.bindevent($("form[role=form]"));
        },
        edit: function () {
            Form.api.bindevent($("form[role=form]"));
        },
    };
    return Controller;
});
